//Demo
layui.use(['form','jquery','layer'], function(){
    var form = layui.form;
    var $ = layui.jquery;
    var layer = layui.layer;
    //监听提交
    form.on('submit(formDemo)', function(data){
        queding();
        return false;
    });
    var result="";
    form.on('radio(shenhe)',function (data) {
        result = data.value;
    })
    queding = function quding() {
        var implementDate = new Date();
        implementDate = getTime(implementDate);

        if(result=="yes"){
            result="4";
        }else{
            result="6";
        }
        var userId=localStorage.getItem("createId");
        var json =
            {
                courseCstatus:result,
                remark:$("#remarks").val(),
                createDate:implementDate,
                userId:userId,
                type:result,
                courseId:$("#id").val(),
                tableName:$("#courseName2").val(),
            }
        $.ajax({
            type:"post",
            url:"/courseTable/updateCstatus",
            dataType:"json",
            data:json,
            success:function (data) {
                if(data){
                    $.ajax({
                        type:"post",
                        url:"/courseTable/addRecord",
                        dataType:"json",
                        data:json,
                        success:function (data) {
                            console.log(data);
                            if(data){
                                alert("审核成功");
                                parent.location.reload();
                            }else{
                                alert("审核失败");
                                parent.location.reload();
                            }
                        }
                    })
                }else{
                    alert("审核失败");
                    parent.location.reload();
                }
            }



        })
    };





    //顶部时间
    function getTime(date){
        var year = date.getFullYear(); //获取完整的年份(4位,1970-????)
        var month = date.getMonth()+1; //获取当前月份(0-11,0代表1月)
        var today = date.getDate(); //获取当前日(1-31)
        var hour = date.getHours(); //获取当前小时数(0-23)
        var minute = date.getMinutes(); //获取当前分钟数(0-59)
        var second = date.getSeconds(); //获取当前秒数(0-59)
        var nowTime;
        nowTime = year+'-'+fillZero(month)+'-'+fillZero(today)+' '+fillZero(hour)+':'+fillZero(minute)+':'+fillZero(second);
        return nowTime;
    };

    //时间的为零操作
    function fillZero(str){
        var realNum;
        if(str<10){
            realNum	= '0'+str;
        }else{
            realNum	= str;
        }
        return realNum;
    }
    cancel = function cancel() {
        var layer=parent.layer;
        layer.close(layer.index);
    }
});